//生产企业维护单
import React from 'react';
import { Card, Row, Radio, Col, Form, DatePicker, Select, Button, Checkbox, Table, Switch, message, TimePicker, Pagination, Input } from 'antd';
import { $http } from 'containers/config/https';
import CommonPagination from 'components/pagination/index';
import Reports from '../../raqSoft/reportsEmbed';
import './style/index.less';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import Moment from 'moment';
import store from 'store';

const { Option } = Select;
const FormItem = Form.Item;
const formItemLayout = {    // label 和input宽度
    labelCol: { span: 8 },
    wrapperCol: { span: 16 },
};
const formItemItem = {
    labelCol: { span: 6 },
    wrapperCol: { span: 16 }
};

const WarehousingSummaryMaintenance = Form.create()(
    class extends React.Component {
        constructor() {
            super();
            this.state = {
                selectLocList: [], //科室列表数据
                selectSupplierList: [],//供应商列表数据
                selectGroupClassList: [],//组类列表数据
                selectInventoryClassificationList: [],//库存分类数据列表
                selectControlClassificationList: [],//管制分类数据列表
                userInfo: {}, //表单数据详情
                outPutListData: [],//输出信息列表
                pageSize: 10,
                page: 1,
                total: 0,
                language: JSON.parse(window.sessionStorage.userData),
                ChineseEnglishSize: [],
                params: {},
                reportName: "singleProductSummary"

            }


        }

        componentDidMount() {
            // 初始化数据
            this.getSelectListData();


        }

        componentWillUnmount() {
            // 组件销毁前将静止让setState修改state的状态，防止内存泄漏
            this.setState = (state, callback) => { return; }
        }

        //清空表格内容
        resetFields = () => {
            this.props.form.resetFields();
            this.setState({ userInfo: {}, rowKey: '', rowData: '' });
        };
        handleReset = () => {
            this.resetFields();

        }
        //导入数据
        importData = () => {

        }
        searchInformation = () => {
            this.setState({ page: 1 }, () => {
                this.getManufacturerList()
            })
        };
        //获取初始化页面的下拉列表数据
        getSelectListData = () => {
            $http.post('urlS', this, {
                code: "02020293",
                data: {
                    params: [],
                    pagination: []
                },
                success: function (res) {
                    let ID = this.state.language.locID;
                    let LocDr = this.state.language.locDesc;

                    this.setState({
                        selectLocList: res.result.selectLocList.result.rows,
                        selectSupplierList: res.result.selectSupplierList,
                        selectGroupClassList: res.result.selectGroupClassList,
                        selectInventoryClassificationList: res.result.selectInventoryClassificationList,
                        selectControlClassificationList: res.result.selectControlClassificationList,
                        userInfo: { ID: ID, LocDr: LocDr },
                    });

                    this.setState({
                        selectLocList: this.state.selectLocList.concat({ ID: ID, LocDr: LocDr })
                    })
                    // userInfo:this.state.concat({ID:ID,LocDr:LocDr})



                }
            });
        }
        // 根据表单获取列表数据
        searchInformation = () => {
            let LocID = this.props.form.getFieldValue('Loc');
            let startDate = this.props.form.getFieldValue('startDate');
            let endDate = this.props.form.getFieldValue('endDate');
            let startTime = this.props.form.getFieldValue('startTime');
            let endTime = this.props.form.getFieldValue('endTime');
            let supplier = this.props.form.getFieldValue('supplier');
            let groupClass = this.props.form.getFieldValue('groupClass');
            let inventoryClassification = this.props.form.getFieldValue('inventoryClassification');
            let controlClassification = this.props.form.getFieldValue('controlClassification');
            let drugName = this.props.form.getFieldValue('drugName');
            let otherDate = this.props.form.getFieldValue('otherDate');
            let reportType = this.props.form.getFieldValue('reportType');
            var tableName = ""
            if (reportType == "singleProductSummary") {
                var tableName = "单品汇总"
            }
            if (reportType == "receiptDocSummary") {
                var tableName = "入库单汇总"
            }
            if (reportType == "supplierGroupSummary") {
                var tableName = "供应商组类汇总"
            }
            if (reportType == "classSetSummary") {
                var tableName = "组类汇总"
            }
            if (reportType == "inventoryClassificationSummary") {
                var tableName = "库存分类汇总"
            } 
            if (reportType == "WarehousingAcceptance") {
                var tableName = "入库验收明细"
            }
            let params = {
                locID: LocID ? LocID : undefined,
                startDate: startDate ? Moment(startDate).format("YYYY-MM-DD") : undefined,
                endDate: endDate ? Moment(endDate).format("YYYY-MM-DD") : undefined,
                tableName: tableName ? tableName : undefined,
                drugName: drugName ? drugName : undefined,
                supplier,
                groupClass,
                inventoryClassification,
                controlClassification
            };
            this.setState({ reportName: reportType, params: params })

            // $http.post('urlS', this, {
            //     code: "02020264",
            //     data: data,
            //     success: function (res) {
            //         if(res.errorCode==0 && res.result.rows.length > 0){
            //             for(let i = 0; i < res.result.rows.length; i++){
            //                 res.result.rows[i].key = i;
            //             }
            //             this.setState({ outPutListData: res.result.rows, total: res.result.total, loading: false});
            //         }else {
            //             this.setState({ outPutListData: [],total:0,loading: false});
            //             if (language.language =='EN'){
            //                 message.error("No related data was found");
            //             }else{
            //                 message.error("没数据");
            //             }
            //             this.props.form.resetFields();
            //         }
            //     }
            // });
        };






        // 页码改变的回调，参数是改变后的页码及每页条数
        onChange = (page, pageSize) => {
            this.setState({ page: page, pageSize: this.state.pageSize }, () => {
                // 重新调用查询方法
                this.getManufacturerList();
            });
        };

        onShowSizeChange = (current, size) => {
            this.setState({ page: current, pageSize: size }, () => {
                // 重新调用查询方法
                this.onChange(current, size);
            })
        };

        // 显示分页总条数
        showTotal(total) {
            return `共 ${total} 条`;
        }
        //页面中英文翻译
        getDetailTableColumns = () => {
            let { language } = this.state;
            let data = {
                params: [{
                    reactCode: ['WarehousingSummaryMaintenance'],
                    compontName: 'WarehousingSummaryMaintenance',
                    type: 'C',
                }]
            }
            $http.post('urlS', this, {
                code: '01040073',
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        this.setState({ ChineseEnglishSize: language.language == 'EN' ? res.result.language.EN : res.result.language.CN })
                    }
                }
            })
        };
        render() {
            const { getFieldDecorator } = this.props.form;
            const { userInfo, ChineseEnglishSize } = this.state;
            return (
                <div className="WarehousingSummaryMaintenance">
                    <Row>
                        <Col span={6}>
                            <Row>
                                <Card
                                    size="small"
                                    title={<div className="card-title-left-icon"><div></div>按钮操作</div>}
                                >
                                    <Col >
                                        <Row >
                                            <Col style={{ textAlign: 'center' }} >
                                                <Button onClick={this.searchInformation}>查询</Button>
                                                <Button type="primary" onClick={this.handleReset} style={{ marginLeft: '20px' }}>清屏</Button>
                                            </Col>
                                        </Row>
                                    </Col>
                                </Card>
                            </Row>
                            <Row>
                                <Col  >
                                    <Form >
                                        <Card
                                            title={<div className="card-title-left-icon"><div></div>查询条件</div>}
                                            size="small"
                                        >
                                            <section className="ant-form-list">
                                                <div style={{ height: store.getState().tableHeight.y + 50 + 'px' }}>
                                                    <Col >
                                                        <Row>
                                                            <Col >
                                                                <FormItem label="科室" {...formItemItem}>
                                                                    {getFieldDecorator('Loc', {
                                                                        initialValue: userInfo.ID ? userInfo.ID : "",
                                                                        rules: [
                                                                            {
                                                                                type: 'text',
                                                                            },
                                                                            {
                                                                                required: false,
                                                                                message: 'Please input your Loc',
                                                                            },
                                                                        ],
                                                                    })(
                                                                        <Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '100%' }}>
                                                                            {this.state.selectLocList.length > 0 && this.state.selectLocList.map(item => {
                                                                                return <Option value={item.ID} key={item.ID} title={item.descripts} seatchprop={item.LocDr}>{item.LocDr}</Option>
                                                                            })}
                                                                        </Select>
                                                                    )}
                                                                </FormItem>
                                                            </Col>
                                                        </Row>
                                                        <Row>
                                                            <Col >
                                                                <FormItem label="开始日期" {...formItemItem}>
                                                                    {getFieldDecorator('startDate', {
                                                                        initialValue: Moment(new Date()),
                                                                        rules: [{ required: false, message: 'Please select startDate!' }]
                                                                    })(
                                                                        <DatePicker
                                                                            format="YYYY-MM-DD"
                                                                            style={{ width: '100%' }}
                                                                        >
                                                                        </DatePicker>
                                                                    )}
                                                                </FormItem>
                                                            </Col>

                                                        </Row>
                                                        <Row>
                                                            <Col >
                                                                <FormItem label="开始时间" {...formItemItem}>
                                                                    {getFieldDecorator('startTime', {
                                                                        rules: [
                                                                            {
                                                                                type: 'object',

                                                                            },
                                                                            {
                                                                                required: false,
                                                                                message: 'Please input your startTime',
                                                                            },
                                                                        ],
                                                                    })(
                                                                        <TimePicker format="HH:mm:ss"
                                                                            style={{ width: '100%' }} />
                                                                    )}
                                                                </FormItem>
                                                            </Col>

                                                        </Row>
                                                        <Row>
                                                            <Col >
                                                                <FormItem label="结束日期" {...formItemItem}>
                                                                    {getFieldDecorator('endDate', {
                                                                        initialValue: Moment(new Date()),
                                                                        rules: [{ required: false, message: 'Please select startDate!' }]
                                                                    })(
                                                                        <DatePicker
                                                                            format="YYYY-MM-DD"
                                                                            style={{ width: '100%' }}
                                                                        >
                                                                        </DatePicker>
                                                                    )}
                                                                </FormItem>
                                                            </Col>
                                                        </Row>
                                                        <Row>
                                                            <Col >
                                                                <FormItem label="结束时间" {...formItemItem}>
                                                                    {getFieldDecorator('endTime', {
                                                                        rules: [
                                                                            {
                                                                                type: 'object',

                                                                            },
                                                                            {
                                                                                required: false,
                                                                                message: 'Please input your endTime',
                                                                            },
                                                                        ],
                                                                    })(
                                                                        <TimePicker format="HH:mm:ss"
                                                                            style={{ width: '100%' }} />
                                                                    )}
                                                                </FormItem>
                                                            </Col>
                                                        </Row>
                                                        <Row>
                                                            <Col >
                                                                <FormItem label="供应商" {...formItemItem}>
                                                                    {getFieldDecorator('supplier', {
                                                                        rules: [
                                                                            {
                                                                                required: false,
                                                                                message: 'Please input your supplier',
                                                                            },
                                                                        ],
                                                                    })(
                                                                        <Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '100%' }}>
                                                                            {this.state.selectSupplierList.length > 0 && this.state.selectSupplierList.map(item => {
                                                                                return <Option value={item.id} key={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>
                                                                            })}
                                                                        </Select>
                                                                    )}
                                                                </FormItem>
                                                            </Col>

                                                        </Row>
                                                        <Row>
                                                            <Col >
                                                                <FormItem label="类组" {...formItemItem}>
                                                                    {getFieldDecorator('groupClass', {
                                                                        rules: [
                                                                            {
                                                                                required: false,
                                                                                message: 'Please input your groupClass',
                                                                            },
                                                                        ],
                                                                    })(
                                                                        <Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '100%' }}>
                                                                            {this.state.selectGroupClassList.length > 0 && this.state.selectGroupClassList.map(item => {
                                                                                return <Option value={item.id} key={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>
                                                                            })}
                                                                        </Select>
                                                                    )}
                                                                </FormItem>
                                                            </Col>

                                                        </Row>
                                                        <Row>
                                                            <Col >
                                                                <FormItem label="库存分类" {...formItemItem}>
                                                                    {getFieldDecorator('inventoryClassification', {
                                                                        initialValue: undefined,
                                                                    })(
                                                                        <Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '100%' }}>
                                                                            {this.state.selectInventoryClassificationList.length > 0 && this.state.selectInventoryClassificationList.map(item => {
                                                                                return <Option value={item.id} key={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>
                                                                            })}
                                                                        </Select>
                                                                    )}
                                                                </FormItem>
                                                            </Col>

                                                        </Row>
                                                        <Row>
                                                            <Col >
                                                                <FormItem label="管制分类" {...formItemItem}>
                                                                    {getFieldDecorator('controlClassification', {
                                                                        initialValue: undefined,
                                                                    })(
                                                                        <Select showSearch optionFilterProp="seatchprop" allowClear style={{ width: '100%' }}>
                                                                            {this.state.selectControlClassificationList.length > 0 && this.state.selectControlClassificationList.map(item => {
                                                                                return <Option value={item.id} key={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>
                                                                            })}
                                                                        </Select>
                                                                    )}
                                                                </FormItem>
                                                            </Col>

                                                        </Row>
                                                        <Row>
                                                            <Col >
                                                                <FormItem label="药品名称" {...formItemItem}>
                                                                    {getFieldDecorator('drugName', {
                                                                        rules: [
                                                                            {
                                                                                type: 'text',

                                                                            },
                                                                            {
                                                                                required: false,
                                                                                message: 'Please input your groupClass',
                                                                            },
                                                                        ],
                                                                    })(
                                                                        <Input style={{ width: '100%' }} />
                                                                    )}
                                                                </FormItem>
                                                            </Col>

                                                        </Row>
                                                        <Row>
                                                            <Col >
                                                                <FormItem {...formItemItem}>
                                                                    {getFieldDecorator('otherDate', {
                                                                        initialValue: [""],

                                                                    })(
                                                                        <Checkbox.Group style={{ marginLeft: "160px", width: '100%' }}>
                                                                            <Row>
                                                                                <Col >
                                                                                    <Checkbox value="returnGoods">是否包含退货</Checkbox>
                                                                                </Col>

                                                                            </Row>
                                                                            <Row>
                                                                                <Col >
                                                                                    <Checkbox value="drugMarker">基本药物标志</Checkbox>
                                                                                </Col>

                                                                            </Row>
                                                                        </Checkbox.Group>,
                                                                    )}
                                                                </FormItem>
                                                            </Col>

                                                        </Row>
                                                        <Row>
                                                            <Col >
                                                                <FormItem label="报表类型" {...formItemItem}>
                                                                    {getFieldDecorator('reportType', {
                                                                        initialValue: 'singleProductSummary',

                                                                    })(
                                                                        <Radio.Group style={{ width: '100%' }}>
                                                                            {/* <Row>
                                                                                <Col>
                                                                                    <Radio value="stockInList">入库单列表</Radio>
                                                                                </Col>
                                                                            </Row> */}
                                                                            <Row>
                                                                                <Col>
                                                                                    <Radio value="singleProductSummary">单品汇总</Radio>
                                                                                </Col>
                                                                            </Row>
                                                                            <Row>
                                                                                <Col>
                                                                                    <Radio value="stockInList">入库药品明细表</Radio>
                                                                                </Col>
                                                                            </Row>
                                                                            <Row>
                                                                                <Col>
                                                                                    <Radio value="supplierGroupSummary">供应商汇总列表</Radio>
                                                                                </Col>
                                                                            </Row>
                                                                            {/* <Row>
                                                                                <Col>
                                                                                    <Radio value="supplierSummary">供应商汇总</Radio>
                                                                                </Col>
                                                                            </Row>
                                                                            <Row>
                                                                                <Col>
                                                                                    <Radio value="supplierDetailsSummary">供应商明细汇总</Radio>
                                                                                </Col>
                                                                            </Row>
                                                                            <Row>
                                                                                <Col>
                                                                                    <Radio value="supplierGroupSummary">供应商组类汇总</Radio>
                                                                                </Col>
                                                                            </Row>
                                                                            <Row>
                                                                                <Col>
                                                                                    <Radio value="classSetSummary">类组汇总</Radio>
                                                                                </Col>
                                                                            </Row>
                                                                            <Row>
                                                                                <Col>
                                                                                    <Radio value="inventoryClassificationSummary">库存分类汇总</Radio>
                                                                                </Col>
                                                                            </Row>
                                                                            <Row>
                                                                                <Col>
                                                                                    <Radio value="receiptDocSummary">入库单汇总</Radio>
                                                                                </Col>
                                                                            </Row>
                                                                            <Row>
                                                                                <Col>
                                                                                    <Radio value="receiptDocSummaryPurchasePrice">入库单（进价）汇总</Radio>
                                                                                </Col>
                                                                            </Row>
                                                                            <Row>
                                                                                <Col>
                                                                                    <Radio value="inventoryProfitAndLossDetails">盘点损益明细</Radio>
                                                                                </Col>
                                                                            </Row>
                                                                            <Row>
                                                                                <Col>
                                                                                    <Radio value="WarehousingAcceptance">入库验收明细</Radio>
                                                                                </Col>
                                                                            </Row> */}
                                                                        </Radio.Group>,

                                                                    )}
                                                                </FormItem>
                                                            </Col>

                                                        </Row>

                                                    </Col>

                                                </div>
                                            </section>
                                        </Card>
                                    </Form>

                                </Col>
                            </Row>
                        </Col>
                        <Col span={18}>


                            <div style={{ height: store.getState().tableHeight.y + 200 + 'px' }}>
                                <Reports raqName={this.state.reportName} params={this.state.params} />
                            </div>

                        </Col >
                    </Row>

                </div>
            )
        }
    }
);
export default WarehousingSummaryMaintenance;